package edu.ucue.ECU.dao;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *Singleton para conexion a la base de datos
 * @author Emily
 */
public class Conexion {
    private static Conexion instancia;
    
    private static Connection conexion;
    
    private Conexion()
    {
              try {
                  Class.forName("org.postgresql.Driver");
                  conexion = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/postgres","postgres","opta");
                  
              } catch(Exception e) {
                  System.out.println(e.getMessage());
              }
    }
    
    
    public static Conexion getInstance()
    {   try {
          if (conexion==null || conexion.isClosed())
              instancia = new Conexion();
          return instancia;
        } catch (SQLException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public Connection getConexion() {
        return conexion;
    }
    
    
}
